import { createRouter, createWebHistory } from 'vue-router'
import index from '../views/admin/index'
import { ElMessage } from "element-plus";

const routes = [
    {
        path: '/',
        redirect: { name: 'admin-home' }
    },
    {
        path: '/admin',
        redirect: { name: 'admin-home' }
    },
    {
        path: '/admin/index',
        name: 'admin',
        component: index,
        redirect: { name: 'admin-home' },
        children: [
            {
                path: '/admin/home',
                name: 'admin-home',
                title:"首页",
                component: () => import("../views/admin/home"),
                meta: { requiresAuth: true, adminType: 0 }
            },
            {
                path: '/admin/userList',
                name: 'admin-userList',
                title:"用户管理",
                component: () => import("../views/admin/userList"),
            },
            {
                path: '/admin/coach',
                name: 'admin-coach',
                title:"教练管理",
                component: () => import("../views/admin/coach"),
                meta: { requiresAuth: true, adminType: 0 }

            },
            {
                path: '/admin/report',
                name: 'admin-report',
                title:"投诉管理",
                component: () => import("../views/admin/report"),
                meta: { requiresAuth: true, adminType: 0}
            },
            {
                path: '/admin/admin',
                name: 'admin-admin',
                title:"管理员管理",
                component: () => import("../views/admin/admin")

            },
            {
                path: '/admin/payType',
                name: 'admin-payType',
                title:"支付供应商管理",
                component: () => import("../views/admin/payType")

            },
            {
                path: '/admin/bill',
                name: 'admin-bill',
                title:"订单管理",
                component: () => import("../views/admin/bill")
            }

        ]
    },
    {
        path: '/admin/login',
        name: '/admin/login',
        component: () => import('../views/admin/login.vue')
    },
    {
        path: '/:pathMatch(.*)*',
        name: '404',
        component: () => import('../views/404')
    }

]

const router = createRouter({
    mode: 'history',
    history: createWebHistory(),
    routes
})

export default router

// 判断该路由是否需要登录权限
// router.beforeEach((to, from, next) => {
//     if (to.meta.requiresAuth) { 
//         if (localStorage.getItem("admin")) {
//             next()  //本地缓存有aid就放行
//         } else {
//             // 未登录,跳转到登陆页面
//             console.log("给我滚", to)
//             ElMessage.error("请重新登录")
//             next({
//                 path: '/admin/login'
//             })
//         }

//     } else {
//         next();
//     }
// });
